﻿using System;
using System.Collections.Generic;

using System.Text;
using NHibernate;
using NHibernate.SqlCommand;

namespace DAL
{
    [Serializable]
    public class EmptyInterceptor : IInterceptor
    {   //前面省略n行代码 

        public virtual SqlString OnPrepareStatement(SqlString sql)
        {

            return sql;

        }


        public void AfterTransactionBegin(ITransaction tx)
        {
            //throw new NotImplementedException();
        }

        public void AfterTransactionCompletion(ITransaction tx)
        {
            //throw new NotImplementedException();
        }

        public void BeforeTransactionCompletion(ITransaction tx)
        {
            //throw new NotImplementedException();
        }

        public int[] FindDirty(object entity, object id, object[] currentState, object[] previousState, string[] propertyNames, NHibernate.Type.IType[] types)
        {
            //throw new NotImplementedException();
            return null;
        }

        public object GetEntity(string entityName, object id)
        {
            //throw new NotImplementedException();
            return null;
        }

        public string GetEntityName(object entity)
        {
            //throw new NotImplementedException();
            return "";
        }

        public object Instantiate(string entityName, EntityMode entityMode, object id)
        {
            //throw new NotImplementedException();
            return null;
        }

        public bool? IsTransient(object entity)
        {
            //throw new NotImplementedException();
            return true;
        }

        public void OnCollectionRecreate(object collection, object key)
        {
            //throw new NotImplementedException();
        }

        public void OnCollectionRemove(object collection, object key)
        {
            //throw new NotImplementedException();
        }

        public void OnCollectionUpdate(object collection, object key)
        {
            //throw new NotImplementedException();
        }

        public void OnDelete(object entity, object id, object[] state, string[] propertyNames, NHibernate.Type.IType[] types)
        {
            //throw new NotImplementedException();
        }

        public bool OnFlushDirty(object entity, object id, object[] currentState, object[] previousState, string[] propertyNames, NHibernate.Type.IType[] types)
        {
            //throw new NotImplementedException();
            return true;
        }

        public bool OnLoad(object entity, object id, object[] state, string[] propertyNames, NHibernate.Type.IType[] types)
        {
            //throw new NotImplementedException();
            return true;
        }

        public bool OnSave(object entity, object id, object[] state, string[] propertyNames, NHibernate.Type.IType[] types)
        {
            //throw new NotImplementedException();
            return true;
        }

        public void PostFlush(System.Collections.ICollection entities)
        {
            //throw new NotImplementedException();
        }

        public void PreFlush(System.Collections.ICollection entities)
        {
            //throw new NotImplementedException();
        }

        public void SetSession(ISession session)
        {
            //throw new NotImplementedException();
        }
    }
    public class MyInterceptor : EmptyInterceptor
    {

        public override NHibernate.SqlCommand.SqlString OnPrepareStatement(NHibernate.SqlCommand.SqlString sql)
        {
            Console.WriteLine(sql.ToString());
            return base.OnPrepareStatement(sql);

        }

    } 

}
